package edu.visualizetion.info.dataprocess;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import com.google.gson.Gson;

/**
 * MR数据的产生的数据处理
 * 
 * @author liukun
 *
 */
public class MRDataProcessor1 {

	public static void main(String[] args) throws IOException {

		// 三个节点的数据，一副本的情况下，文件不可切分的情况下，逻辑是不可切分的情况，只会启动一个map任务，观察数据的传输

		// 16 作为数据的处理节点，会有大量的15，17的数据通信发送给16
		List<Datapoint> datas = new ArrayList<>();

		long time = 1;
		String s16 = "192.168.130.16";
		String s15 = "192.168.130.15";
		String s17 = "192.168.130.17";

		// 0-50的数据
		int cpus16 = 35;
		int cpus15 = 20;
		int cpus17 = 33;

		int cpuchange = 10;

		int mems15 = 50;
		int mems16 = 30;
		int mems17 = 40;

		int memchange = 4;

		float netSend = 0.0025f;
		float netSecv = 0.0022f;

		Random random = new Random();
		for (int i = 1; i <= 69; i++) {
			System.out.println(i);
			int cpu = random.nextInt(cpuchange);
			int mem = random.nextInt(memchange);
			Datapoint datapoints15 = new Datapoint(String.valueOf(i), s16, String.valueOf(cpus16 + cpu),
					String.valueOf(mems16 + mem), String.valueOf(100 - mems16 - mem), String.valueOf(netSend),
					String.valueOf(netSecv), "", "");
			datas.add(datapoints15);
		}
		// 50-120的数据,发送数据出现几个增加点，60-65 80-88 s15
		// 70-74 s17 90-95 s17
		// 60-90 s16 接受变化
		mems16 = mems16 + 10;
		for (int i = 63; i <= 90; i++) {
			System.out.println(i);
			int cpu = random.nextInt(cpuchange+20);
			int mem = random.nextInt(memchange);
			netSecv = 10f + random.nextFloat() * 10;
			
			Datapoint datapoints15 = new Datapoint(String.valueOf(i), s16, String.valueOf(cpus16 + cpu),
					String.valueOf(mems16 + mem), String.valueOf(100 - mems16 - mem), String.valueOf(netSend),
					String.valueOf(netSecv), "", "");
			datas.add(datapoints15);
		}

		// 121-151
		for (int i = 91; i <= 115; i++) {
			System.out.println(i);
			int cpu = random.nextInt(cpuchange+20);
			int mem = random.nextInt(memchange);
			netSecv = 10f + random.nextFloat() * 10;
			Datapoint datapoints15 = new Datapoint(String.valueOf(i), s16, String.valueOf(cpus16 + cpu),
					String.valueOf(mems16 + mem), String.valueOf(100 - mems16 - mem), String.valueOf(netSend),
					String.valueOf(netSecv), "", "");
			datas.add(datapoints15);
		}
		mems16 = mems16-10;
		for (int i = 116; i <= 150; i++) {
			System.out.println(i);
			int cpu = random.nextInt(cpuchange);
			int mem = random.nextInt(memchange);
			Datapoint datapoints15 = new Datapoint(String.valueOf(i), s16, String.valueOf(cpus16 + cpu),
					String.valueOf(mems16 + mem), String.valueOf(100 - mems16 - mem), String.valueOf(netSend),
					String.valueOf(netSecv), "", "");
			datas.add(datapoints15);
		}
		
		System.out.println(datas);
		Gson gson = new Gson();
		String json = gson.toJson(datas);
		FileWriter fileWriter = new FileWriter(s16);
		fileWriter.write(json);
		fileWriter.close();
	}
}
